from flask import Flask, session
from flask import render_template,url_for
from flask import request
from numpy import append 
from flask_session import Session
from inc import *
import sqlite3
import webbrowser
from flask import g


app = Flask(__name__,static_folder=str(root/'web/manage'),template_folder=str(root/'web/manage'))
app.secret_key = "My Secret key"  # right


@app.route('/')
def index(name=None):
    session["newKey"] = 'asdqwe123'
    return render_template('index.html', name=name)
@app.route('/test' ,methods=['POST', 'GET'])
def test():
    return "getkc"+request.args.get('key', '')
@app.route('/getstudentlist' ,methods=['GET','POST'])
def getstudentlist():
    l=['id','name','class','grade']
    r=[]
    for i in l:
        if (request.args.get(i) != None):
            r.append(f"{i} like \'%{request.args.get(i)}%\'")
    sql= "select * from main"
    if(len(r)!=0):
        sql=sql+" where "+" and ".join(r)
    r=query_db(sql,keys=True)
    return({"code":0,"msg": "","count": len(r),"data": r})
port=18080
if __name__== '__main__':
    # webbrowser.open("http://[::1]:{0}".format(port))    
    app.jinja_env.auto_reload = True
    app.config['TEMPLATES_AUTO_RELOAD'] = True
    app.DEBUG=True
    app.run(
        debug=True,
        host = '::',
        port = port
    )
    